#include <jmlib/unitTester/UnitTesterRegistrator.h>
#include <jmlib/unitTester/asserts.h>

#include <jmlib/csv/CsvReader.h>

#include <vector>
#include <sstream>

namespace jmtests {
	
	//struct ColumnInterface {	
	//	template<typename T>
	//	virtual void addValueCell(T value) = 0;
	//};

	//struct DataTragetInterface {
	//	virtual void addColumns(size_t count) = 0;
	//	virtual ColumnInterface* getColumn(size_t columnIndex) = 0;
	//};


	struct ColumnTestImpl {
		void addValueCell(jmlib::NoType v) { assert(false); }
		void addValueCell(int v) { ints_.push_back(v);}
		void addValueCell(const std::string& v) { strings_.push_back(v);}
		std::vector<int> ints_;
		std::vector<std::string> strings_;
	};

	struct DataTargetTestImpl {
		void addColumns(size_t count) {
			for (size_t i = 0; i < count; ++i) {
				columns_.push_back(ColumnTestImpl());
			}
		}
		size_t getColumnCount() const { return columns_.size(); }
		ColumnTestImpl* getColumn(size_t i) { return &columns_.at(i);}
		std::vector<ColumnTestImpl> columns_;
	};

	struct TestX : public jmlib::UnitTest {
		virtual void test01() {
			jmlib::CsvReader<DataTargetTestImpl, int, std::string> reader;
			std::stringstream stream;
			int data[3][3] = {{1,2,3},{0,0,0},{10,11,12}};
			for (int row = 0; row < 3; ++row) {
				for (int col = 0; col < 3; ++col) {
					stream << data[col][row];
					if (col+1 < 3 ) stream << ",";
				}
				stream << "\n";
			}
			std::string d = stream.str();
			//stream << "1,2,3\n0,0,0\n10,11,12";
			DataTargetTestImpl t;
			reader.readCsv(&t,stream);
			for (int col = 0; col < 3; ++col) {
				for (int row = 0; row < 3; ++row) {			
					JM_EXPECT_VALUE(t.getColumn(col)->ints_.at(row), data[col][row]);
				}
			}		
		}
	};

	static jmlib::UnitTesterRegistrator r(new TestX());
} // namespace jmtests
